<?php
 require 'UsuariosController.php';

class FrontController 
{

    private $controller = '';
    private $action = '';
    private $params = array();


    public function parseURI()
    {        

        $path = trim(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), "/");
        $path = str_replace("pw3-201301-hotel/src/", "", $path);
        $path = preg_replace('/[^a-zA-Z0-9]\//', "", $path);
        $path = explode("/", $path);

        if (!empty($path)) {
            $this->controller = $path[0];

            if (isset($path[1])) {
                $this->action = $path[1];
            }
        }

        if (!empty($this->controller)) {
            $this->controller .= 'Controller';
        }
        
        unset($path[0]);
        unset($path[1]);

        $this->params = $path;


    }

    public function run()
    {
        
        call_user_func_array(array(new $this->controller, $this->action), $this->params);
    }
}